package com.hdu.seckilldemo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

//@Configuration
public class RabbitMQConfigHeads {
    private static final String QUEUE_HEAD01 = "queue_header01";
    private static final String QUEUE_HEAD02 = "queue_header02";
    private static final String EXCHANGE = "headerEXCHANGE";

    @Bean
    public Queue queue_header01(){
        return new Queue(QUEUE_HEAD01);
    }

    @Bean
    public Queue queue_header02(){
        return new Queue(QUEUE_HEAD02);
    }

    @Bean
    public HeadersExchange headersExchange(){
        return new HeadersExchange(EXCHANGE);
    }

    @Bean
    public Binding binding_header01(){
        //配置 header中匹配的关键词
        HashMap<String,Object> map = new HashMap<>();
        map.put("color","red");
        map.put("speed","low");
        // top中的color 或者speed满足任意一个要求就放入队列
        return BindingBuilder.bind(queue_header01()).to(headersExchange()).whereAny(map).match();
    }

    @Bean
    public Binding binding_header02(){
        //配置 header中匹配的关键词
        HashMap<String,Object> map = new HashMap<>();
        map.put("color","red");
        map.put("speed","low");
        // top中的color 和 speed都满足才能放入队列
        return BindingBuilder.bind(queue_header02()).to(headersExchange()).whereAll(map).match();
    }
}

